package org.csu.gp_store.bo;

import lombok.Data;
import org.csu.gp_store.entity.Company;
import org.csu.gp_store.entity.Evaluation;
import org.csu.gp_store.entity.Item;
import org.csu.gp_store.entity.Product;

import java.math.BigDecimal;
import java.util.List;

@Data
public class ItemBO {


    private String itemID;
    private String productID;
    private String productName;
    private String description;
    private String companyID;
    private BigDecimal price;
    private int status;
    private String companyName;
    private String companyDescription;
    private String companyEmail;
    private String companyAddress;
    private String image;
    private String style;
    private List<Evaluation> evaluationList;
    private double avg_rate;

    public ItemBO() {

    }

    public static ItemBO toItemBO(Company company, Product product, Item item,List<Evaluation> evaluationList) {
        ItemBO itemBO = new ItemBO();
        itemBO.setItemID(String.valueOf(item.getItemID()));
        itemBO.productID = String.valueOf(product.getProductID());
        itemBO.productName = product.getProductName();
        itemBO.companyID = String.valueOf(product.getCompanyID());
        itemBO.price = item.getPrice();
        itemBO.status = item.getStatus();
        itemBO.description = product.getDescription();
        itemBO.companyName = company.getCompanyName();
        itemBO.companyDescription = company.getDescription();
        itemBO.companyEmail = company.getEmail();
        itemBO.companyAddress = company.getAddress();
        itemBO.setImage(item.getImage());
        itemBO.setStyle(item.getStyle());
        itemBO.setEvaluationList(evaluationList);
        double rate=0;
        for (Evaluation evaluation :evaluationList){
            rate+=evaluation.getRate();
        }
        itemBO.setAvg_rate(rate/evaluationList.size());
        return itemBO;
    }
    public static Item ItemBOToItem(ItemBO itemBO) {
        Item item =new Item();
        item.setItemID(Long.valueOf(itemBO.getItemID()));
        item.setProductID(Long.valueOf(itemBO.getProductID()));
        item.setPrice(itemBO.getPrice());
        item.setStatus(itemBO.getStatus());
        item.setImage(itemBO.getImage());
        item.setStyle(itemBO.getStyle());
        return item;
    }


}
